package com.edu.bean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

/**
 * @Author:mx
 * @Date:2025/11/3-15:10:02
 */

//@Controller("u1")
//@Service("u1")
//@Repository("u1")
@Component("u1")
//@Scope("singleton")
//@Lazy(false)
public class User {

    /*
    *   @Value 直接放在属性上面是 反射注入
    * */
    @Value("1")
    private int userId;

    private String username;

    private String password;

/*    @Autowired
    @Qualifier("c2")*/

    @Resource(name="c2")
    private Car car;

    private int age;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getUserId() {
        return userId;
    }

//    @Value("1")
    public void setUserId(int userId) {
        System.out.println("执行了userId的 set方法");
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Car getCar() {
        return car;
    }


    public void setCar(Car car) {
        this.car = car;
    }

    @Override
    public String toString() {
        return "User{" +
                "userId=" + userId +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", car=" + car +
                ", age=" + age +
                '}';
    }

    public User() {
        System.out.println("执行了无参数构造方法");
    }


//    public User( @Value("10")int userId) {
//        System.out.println("执行了有参数构造方法");
//        this.userId = userId;
//    }

    @PostConstruct
    public void init(){
        System.out.println("执行了初始化");
    }

    @PreDestroy
    public void end(){
        System.out.println("执行了销毁方法");
    }
}
